/**
 * @Author: oldTea
 * @CreateTime: 2024-11-26
 * @Description: LcckSupport的线程阻塞与唤醒 peak  unpeak
 * @Version: 1.0
 */
package com.ambition.demo.juc;

import java.util.concurrent.locks.LockSupport;

/**
 *@Author: oldTea
 *@CreateTime: 2024-11-26
 *@Description: LcckSupport的线程阻塞与唤醒 peak  unpeak
 *@Version: 1.0
 */
public class LockSupportDemo{

    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            System.out.println("A线程被阻塞之前");
            LockSupport.park();
            System.out.println("A线程被B线程唤醒");
        });

        t.start();


        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("B线程唤醒A线程");
                LockSupport.unpark(t);
            }
        }).start();
    }
}


